package StudyCode.summary.mycollection;

import java.util.*;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GetsANewSetThatIsTheInterleavedUnionOfTheSetProvided {
	public static void main(String[] argv) {
		List keySets = java.util.Arrays.asList("科技与人文", "www.tah1986.com");
		System.out.println(fanIn(keySets));
	}

	static Map<String, String> TEST_ENTRIES;

	static Set<String> fanIn(final Set<String> keySet1, final Set<String> keySet2) {
		final List<Set<String>> keySets = new ArrayList<Set<String>>();
		keySets.add(keySet1);
		keySets.add(keySet2);
		return fanIn(keySets);
	}

	static Set<String> fanIn(final Set<String> keySet1,
	                         final Set<String> keySet2, final Set<String> keySet3) {
		final List<Set<String>> keySets = new ArrayList<Set<String>>();
		keySets.add(keySet1);
		keySets.add(keySet2);
		keySets.add(keySet3);
		return fanIn(keySets);
	}

	static Set<String> fanIn(final Set<String> keySet1,
	                         final Set<String> keySet2, final Set<String> keySet3,
	                         final Set<String> keySet4) {
		final List<Set<String>> keySets = new ArrayList<Set<String>>();
		keySets.add(keySet1);
		keySets.add(keySet2);
		keySets.add(keySet3);
		keySets.add(keySet4);
		return fanIn(keySets);
	}

	private static Set<String> fanIn(final List<Set<String>> keySets) {
		final Set<String> union = new LinkedHashSet<>();

		for (final String key : TEST_ENTRIES.keySet()) {
			for (final Set<String> keySet : keySets) {
				if (keySet.contains(key)) {
					union.add(key);
					break;
				}
			}
		}
		return union;
	}
}